package cn.bs.busuo.mall.dao.persist.repository.impl;

import cn.bs.busuo.common.pojo.vo.PageData;
import cn.bs.busuo.common.util.PageInfoToPageDataConverter;
import cn.bs.busuo.mall.dao.persist.mapper.CommentMapper;
import cn.bs.busuo.mall.dao.persist.repository.ICommentRepository;
import cn.bs.busuo.mall.pojo.entity.Comment;
import cn.bs.busuo.mall.pojo.vo.CommentListItemVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class CommentRepositoryImpl implements ICommentRepository {
    @Autowired
    private CommentMapper commentMapper;

    @Override
    public int insert(Comment comment) {
        return commentMapper.insert(comment);
    }

    @Override
    public PageData<CommentListItemVO> list(Long goodsId, Integer pageNum, Integer pageSize){
        PageHelper.startPage(pageNum, pageSize);
        List<CommentListItemVO> list = commentMapper.list(goodsId);
        PageInfo<CommentListItemVO> pageInfo = new PageInfo<>(list);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }
}
